package com.gsoe.auth.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gsoe.auth.po.Power;
import com.gsoe.auth.mapper.PowerMapper;
import com.gsoe.auth.vo.RolePermissionVO;
import com.gsoe.auth.service.PowerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 权限表 服务实现类
 * </p>
 *
 * @author xiaoma
 * @since 2024-11-11
 */
@Service
public class PowerServiceImpl extends ServiceImpl<PowerMapper, Power> implements PowerService {
    @Autowired
    private PowerMapper powerMapper;


    @Override
    public RolePermissionVO getRolePermission(Long roleId) {
        List<Power> rolePermissionList = powerMapper.getRolePermission(roleId);
        if(rolePermissionList==null){
            rolePermissionList=new ArrayList<>();
        }
        List<Power> remainPermissionList = new ArrayList<>();
        List<Power> powerList = list();
        List<Power> finalRolePermissionList = rolePermissionList;
        powerList.forEach(p->{
            if(!finalRolePermissionList.contains(p)){
                remainPermissionList.add(p);
            }
        });

        RolePermissionVO rolePermissionVO=new RolePermissionVO();
        rolePermissionVO.setRolePermissionList(rolePermissionList);
        rolePermissionVO.setRemainPermissionList(remainPermissionList);
        return rolePermissionVO;

    }
}
